package cn.qiyu5522.controller;


import cn.qiyu5522.domain.DTO.RoleAddDTO;
import cn.qiyu5522.domain.DTO.RoleChangeDTO;
import cn.qiyu5522.domain.entity.ResponseResult;
import cn.qiyu5522.service.RoleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 角色信息表 前端控制器
 * </p>
 *
 * @author Tonkey
 * @since 2024-04-22
 */
@RestController
@RequestMapping("/system/role")
public class RoleController {

    @Resource
    private RoleService roleService;
    @GetMapping("/list")

    public ResponseResult list(@RequestParam Integer pageNum,
                               @RequestParam Integer pageSize,
                               @RequestParam(required = false) String roleName,
                               @RequestParam(required = false) String status) {
        return roleService.getRoleListByCondition(pageNum,pageSize,roleName,status);
    }

    @PutMapping("/changeStatus")
    public ResponseResult changeStatus(@RequestBody RoleChangeDTO roleChangeDTO){
        return roleService.changeStatus(roleChangeDTO);
    }

    @PostMapping
    public ResponseResult addRole(@RequestBody RoleAddDTO roleAddDTO){
        return roleService.addRole(roleAddDTO);
    }


    @GetMapping("/{id}")
    public ResponseResult getRoleById(@PathVariable Long id){
        return roleService.getRoleById(id);
    }

}
